#include<bits/stdc++.h>
using namespace std;
int main()
{
	freopen("candy.in","r",stdin);
	freopen("candy.out","w",stdout);
	long long n,a,b,x;
	scanf("%ld%ld%ld",&n,&a,&b);
	x=a%n;
	while(x<n-1&&a<b){
		x++;
		a++;
	}
	printf("%ld",x);
	fclose(stdin);
	fclose(stdout);
}
